﻿//MessageDispatcher.cs
//Copyright (c) 2013 StockSharp LLC, all rights reserved.
//This code module is part of StockSharp library.
//This code is licensed under the GNU GENERAL PUBLIC LICENSE Version 3.
//See the file License.txt for the license details.
//More info on: http://stocksharp.com

namespace StockSharp.Plaza.Wrappers
{
	using System;
	using System.Runtime.InteropServices;

	/// <summary>
	/// Внутренний класс для обработки Plaza сообщений.
	/// </summary>
	[ComVisible(true)]
	[CLSCompliant(false)]
	public sealed class MessageDispatcher : P2ClientGateMTA32.IP2AsyncSendEvent2, P2ClientGateMTA64.IP2AsyncSendEvent2
	{
		private readonly Action<IMessageWrapper, uint, long> _handler;

		internal MessageDispatcher(Action<IMessageWrapper, uint, long> handler)
		{
			if (handler == null)
				throw new ArgumentNullException("handler");

			_handler = handler;
		}

		/// <summary>
		/// Результат доставки сообщения.
		/// </summary>
		/// <param name="reply">Указатель на интерфейс сообщения типа Reply.</param>
		/// <param name="errCode">Код ошибки. Возможные значения.</param>
		/// <param name="eventParam">Дополнительный параметр.</param>
		void P2ClientGateMTA32.IP2AsyncSendEvent2.SendAsync2Reply(P2ClientGateMTA32.CP2BLMessage reply, uint errCode, long eventParam)
		{
			_handler(new MessageWrapper32(reply), errCode, eventParam);
		}

		/// <summary>
		/// Результат доставки сообщения.
		/// </summary>
		/// <param name="reply">Указатель на интерфейс сообщения типа Reply.</param>
		/// <param name="errCode">Код ошибки. Возможные значения.</param>
		/// <param name="eventParam">Дополнительный параметр.</param>
		void P2ClientGateMTA64.IP2AsyncSendEvent2.SendAsync2Reply(P2ClientGateMTA64.CP2BLMessage reply, uint errCode, long eventParam)
		{
			_handler(new MessageWrapper64(reply), errCode, eventParam);
		}
	}
}